<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%
	response.setHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
	request.setCharacterEncoding("UTF-8");
	String num = request.getParameter("num");
	String tingtitle = request.getParameter("tingtitle");
	String tingcontent = request.getParameter("tingcontent");
	//String tingtitle = new String(request.getParameter("tingtitle").getBytes("8859_1"), "utf-8");
	//String tingcontent = new String(request.getParameter("tingcontent").getBytes("8859_1"), "utf-8");
	String tingtheme = request.getParameter("tingtheme");
	String tingdate = request.getParameter("tingdate");
	String tingtime = request.getParameter("tingtime");
	//tingcontent = tingcontent.replace("\n","<br>"); // 줄바꿈 값을 <br>로 
	//tingcontent = tingcontent.replace("\u0020","&nbsp;"); // 띄어쓰기를 &nbsp;로 
	String date = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
	String time = new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date());
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
		
		String update = "update Ting set Title = ?, Content = ?, Theme = ?, StartDate = ?, StartTime = ?, Date = ?, Time= ? where Number = ?;";
		pstmt = conn.prepareStatement(update);
		pstmt.setString(1, tingtitle);
		pstmt.setString(2, tingcontent);
		pstmt.setString(3, tingtheme);
		pstmt.setString(4, tingdate);
		pstmt.setString(5, tingtime);
		pstmt.setString(6, date);
		pstmt.setString(7, time);
		pstmt.setString(8, num);
		pstmt.executeUpdate();
		
		JSONObject jo = new JSONObject();
		jo.put("success", "true");
		out.print(jo);	
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>